<template>
	<view class="home">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in swipers" :key="index">
				<view class="swiper-item">
					<image :src="item.image_src" mode="widthFix"></image>
				</view>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>

		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="title">
				推荐商品
			</view>
			<goods-list :goods="goods"></goods-list>
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				swipers: [],
				goods: [],
				navs: [{
					icon: 'iconfont icon-ziyuan',
					title: '黑马超市',
					path: '/pages/goods_list/goods_list'
				}, {
					icon: 'iconfont icon-guanyuwomen',
					title: '联系我们',
					path: '/pages/contact/contact'
				}, {
					icon: 'iconfont icon-tupian',
					title: '社区图片',
					path: '/pages/pics/pics'
				}, {
					icon: 'iconfont icon-shipin',
					title: '学习视频',
					path: '/pages/videos/videos'
				}, ]
			}
		},
		onLoad() {
			this.getSwipers()
			this.getGoodsList()
		},
		components: {
			"goods-list": goodsList
		},
		methods: {
			// 获取轮播图数据
			async getSwipers() {
				const res = await this.$myRequest({
					url: '/home/swiperdata'
				})
				console.log('获取轮播图数据')
				console.log(res)
				this.swipers = res.data.message
			},
			//获取商品列表
			async getGoodsList() {
				const res = await this.$myRequest({
					url: '/goods/search'
				})
				console.log('获取商品列表')
				console.log(res)
				this.goods = res.data.message.goods
			},
			//导航点击的处理函数
			navItemClick(url) {
				console.log(url)
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 340rpx;

			image {
				width: 100%;
			}
		}

		.nav {
			display: flex;

			.nav_item {
				flex: 1;
				text-align: center;

				view {
					height: 120rpx;
					width: 120rpx;
					background-color: $shop-color;
					border-radius: 60rpx;
					color: #fff;
					margin: 10px auto;
					line-height: 120rpx;
					font-size: 50rpx;
				}


				text {
					font-size: 30rpx;
				}
			}

		}

		.hot_goods {
			margin-top: 30rpx;
			background: #f0eef0;
			overflow: hidden;

			.title {
				background: #ffffff;
				color: $shop-color;
				height: 100rpx;
				margin: 10rpx 0;
				display: flex;
				justify-content: center;
				align-items: center;
			}


		}
	}
</style>
